<?php
/*
	Copyright 2006, 2007, 2008, 2009, 2010 Bastiaan Grutters
    
    This file is part of Ages of Strife website.

    Ages of Strife website is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ages of Strife website is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ages of Strife website.  If not, see <http://www.gnu.org/licenses/>.
 */
include( '../global/initialize.php' );

aos_header( 'Diplomacy' );

$query = "SELECT access, faction_id " .
		"FROM faction_member " .
		"WHERE ruler_id = " . $_SESSION[ 'ruler_id' ] . " AND invited = 0 AND requested = 0";
$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
$row = mysql_fetch_array( $result, MYSQL_ASSOC );
if( isset( $row[ 'access' ] ) && $row[ 'access' ] >= 10 ) {
	$query = "SELECT * " .
			"FROM faction " .
			"WHERE faction_id = " . $row[ 'faction_id' ];
	$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
	$row = mysql_fetch_array( $result, MYSQL_ASSOC );
	
	$query2 = "SELECT count(*) " .
			"FROM village " .
			"JOIN faction_member ON faction_member.ruler_id = village.ruler_id " .
			"WHERE requested = 0 AND invited = 0 AND faction_id = " . $row[ 'faction_id' ];
	$result2 = mysql_query( $query2 ) or die( "Query failed : " . mysql_error() );
	$row2 = mysql_fetch_array( $result2, MYSQL_ASSOC );
	$villages = $row2[ 'count(*)' ];
?>
					<div class="blok">
<?php
	printDiplomacyTab();
?>
					</div>
					<br />
					<div class="blok">
						<strong><?php transprint( 'Faction settings' ); ?>:</strong><br />
						<form method="post" action="action/save_settings.php">
							<?php transprint( 'Tax percentage' ); ?>(0-100): <input type="text" size="2" name="tax" value="<?php print( $row[ 'tax_set' ] ) ?>" />%<br />
							<?php transprint( 'Recruitment message' ); ?>: <input type="text" size="40" name="recruitment" value="<?php print( $row[ 'recruitment' ] ); ?>" /><br />
							<?php transprint( 'Message of the day' ); ?>:<br />
							<textarea name="text" cols="40" rows="5"><?php print( stripslashes( $row[ 'motd' ] ) ); ?></textarea><br />
							<strong><?php transprint( 'Economic policies' ); ?></strong><br />
<?php
	if( $row[ 'farm_support' ] == '1' ) {
		$checked = " checked";
	}
	else {
		$checked = "";
	}
	print( "<input type=\"checkbox\" name=\"farm_support\"" . $checked . " /> " . translate( 'support farmers' ) . ", " .
			translate( 'expected cost' ) . ": <strong class=\"gold\">" . number_format( $villages * 4 ) . "</strong> " . translate( 'gold per turn' ) . ", " .
			translate( 'gives 10% more <strong class="food">food</strong> output for all faction members' ) . "<br />\r\n" );
	if( $row[ 'coal_support' ] == '1' ) {
		$checked = " checked";
	}
	else {
		$checked = "";
	}
	print( "<input type=\"checkbox\" name=\"coal_support\"" . $checked . " /> " . translate( 'support coal miners' ) . ", " .
			translate( 'expected cost' ) . ": <strong class=\"gold\">" . number_format( $villages * 3 ) . "</strong> " . translate( 'gold per turn' ) . ", " .
			translate( 'gives 10% more <strong class="coal">coal</strong> output for all faction members' ) . "<br />\r\n" );
	if( $row[ 'iron_support' ] == '1' ) {
		$checked = " checked";
	}
	else {
		$checked = "";
	}
	print( "<input type=\"checkbox\" name=\"iron_support\"" . $checked . " /> " . translate( 'support iron miners' ) . ", " .
			translate( 'expected cost' ) . ": <strong class=\"gold\">" . number_format( $villages * 3 ) . "</strong> " . translate( 'gold per turn' ) . ", " .
			translate( 'gives 10% more <strong class="iron">iron</strong> output for all faction members' ) . "<br />\r\n" );
	
	if( $row[ 'housing_support' ] == '1' ) {
		$checked = " checked";
	}
	else {
		$checked = "";
	}
	print( "<input type=\"checkbox\" name=\"housing_support\"" . $checked . " /> " . translate( 'subsidize housing' ) . ", " .
			translate( 'expected cost' ) . ": <strong class=\"gold\">" . number_format( $villages * 2 ) . "</strong> " . translate( 'gold per turn' ) . ", " .
			translate( 'gives 10% more <strong class="houses">houses</strong> for all faction members' ) . "<br />\r\n" );
	
	
	print( "<strong>" . translate( 'Military policies' ) . "</strong><br />\r\n" );
	if( $row[ 'draft' ] == '1' ) {
		$checked = " checked";
	}
	else {
		$checked = "";
	}
	print( "<input type=\"checkbox\" name=\"draft\"" . $checked . " /> " . translate( 'higher draft rates' ) . ", " .
			translate( 'expected cost' ) . ": <strong id=\"gold\">" . number_format( $villages * 3 ) . "</strong> " . translate( 'gold per turn' ) . ", " .
			translate( 'gives 50% more recruits per turn for all faction members' ) . "<br />\r\n" );
	if( $row[ 'alert' ] == '1' ) {
		$checked = " checked";
	}
	else {
		$checked = "";
	}
	print( "<input type=\"checkbox\" name=\"alert\"" . $checked . " /> " . translate( 'armies on high alert' ) . ", " .
			translate( 'expected cost' ) . ": <strong id=\"gold\">" . number_format( $villages * 6 ) . "</strong> " . translate( 'gold per turn' ) . ", " .
			translate( 'increases all faction armies attack and defense by 5%' ) . "<br />\r\n" );
	if( $row[ 'nationalism' ] == '1' ) {
		$checked = " checked";
	}
	else {
		$checked = "";
	}
	print( "<input type=\"checkbox\" name=\"nationalism\"" . $checked . " /> " . translate( 'encourage nationalism' ) . ", " .
			translate( 'expected cost' ) . ": <strong id=\"gold\">" . number_format( $villages * 4 ) . "</strong> " . translate( 'gold per turn' ) . ", " .
			translate( '15% more of our villagers are willing to fight enemies when they try to conquer our villages' ) . "<br />\r\n" );
	print "<input type=\"submit\" value=\"" . translate( 'save settings' ) . "\" /></form>";
}
else {
	print "<div class=\"blok\">\r\n";
	transprint( "You don't access to this page." );
}
?>
				</div>
<?php
aos_footer();
?>
